package linuxbox.common.taglib;

import java.io.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import javax.servlet.http.*;
import java.util.*;

import linuxbox.BoxStatic;

/**
 * This class displays a Minute list in the SELECT tag.
 */
public class MinuteList extends TagSupport
{
  protected boolean allowNull = false;
  protected int selected = -1;
  protected int timeInterval = 30;

  public int doStartTag() throws JspException
  {
    try
    {
      JspWriter out = pageContext.getOut();

      if (allowNull)
        out.print("<option value=-1>Minute</option>");

      int count = 60/timeInterval;
      if (count < 1)
        count = 2;
      for(int i=0;i<count;i++)
      {
        if ( selected/timeInterval == i)
          out.print("<option value=\""+i*timeInterval+"\" selected>:"+i*timeInterval+"</option>");
        else
          out.print("<option value=\""+i*timeInterval+"\">:"+i*timeInterval+"</option>");
      }

      out.flush();
    }
    catch(Exception e)
    {
      e.printStackTrace();
      throw new JspException(e.getMessage());
    }

    return SKIP_BODY;
  }

  public void setTimeinterval(int aValue)
  {
    timeInterval = aValue;
  }

  public void setAllownull(String aValue)
  {
    allowNull = new Boolean(aValue).booleanValue();
  }

  public void setSelected(int aValue)
  {
    selected = aValue;
  }
}
